package chances.epg.data.taglib;

import java.util.Date;
import java.util.List;

import javax.servlet.jsp.JspException;

import org.apache.commons.lang.StringUtils;

import chances.epg.data.PageBean;
import chances.epg.data.ScheduleVO;
import chances.epg.data.taglib.page.PageInfo;
import chances.epg.entity.content.EpgSchedule;
import chances.epg.entity.content.ScheduleTimer;

public class ScheduleFilterTag extends ScheduleBaseTag {

	private static final long serialVersionUID = 1L;
	private String var;
	private String mainFolder;
	private String tag;
	private int size = 10;// 条目数
	private int playStatus;
	private Date endTime;
	private Date startTime;
	private String channelCode;

	@Override
	public int doStartTag() throws JspException {
		ScheduleVO scheduleVO = new ScheduleVO();
		scheduleVO.setChannelCode(this.channelCode);
		scheduleVO.setMainFolder(this.mainFolder);
		scheduleVO.setTag(this.tag);
		if (StringUtils.isNotBlank(this.getPageName())) {
			this.queryScheduleByPage(scheduleVO);
		} else {
			this.queryScheduleBySize(scheduleVO);
		}
		return super.doStartTag();
	}

	public void queryScheduleBySize(ScheduleVO scheduleVO) {
		List<EpgSchedule> result = null;
		ScheduleTimer scheduleTimer = new ScheduleTimer();
		scheduleTimer.setStartTime(this.startTime);
		scheduleTimer.setEndTime(this.endTime);
		result = this.getScheduleService().listSchedule(scheduleVO, scheduleTimer, this.start, this.size);
		setCollectionResult(result);
	}

	public void queryScheduleByPage(ScheduleVO scheduleVO) {
		PageInfo pageInfo = this.createPageInfo(size);
		PageBean pageBean = pageInfo.getPageBean();
		pageBean.setSkip(this.start);
		List<EpgSchedule> result = null;
		ScheduleTimer scheduleTimer = new ScheduleTimer();
		scheduleTimer.setStartTime(this.startTime);
		scheduleTimer.setEndTime(this.endTime);
		result = this.getScheduleService().listSchedule(scheduleVO, scheduleTimer, pageBean);
		this.setPageInfo(pageInfo);
		setCollectionResult(result);
	}



	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}

	public String getMainFolder() {
		return mainFolder;
	}

	public void setMainFolder(String mainFolder) {
		this.mainFolder = mainFolder;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	};

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getPlayStatus() {
		return playStatus;
	}

	public void setPlayStatus(int playStatus) {
		this.playStatus = playStatus;
	}

	public String getChannelCode() {
		return channelCode;
	}

	public void setChannelCode(String channelCode) {
		this.channelCode = channelCode;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

}
